package com.estar.assistsurvy.adapter;

import java.util.ArrayList;

import com.estar.assistsurvy.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MessageTypeListAdapter extends BaseAdapter {

	private ArrayList<String> list;
	private LayoutInflater inflater;
	public MessageTypeListAdapter(ArrayList<String> list, Context context) {
		super();
		this.list = list;
		inflater=LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if(convertView==null){
			convertView=inflater.inflate(R.layout.listview_messagetype, null);
			holder=new ViewHolder();
			holder.typeName=(TextView) convertView.findViewById(R.id.typeName);
			holder.icon_duigou=(ImageView) convertView.findViewById(R.id.icon_duigou);
			convertView.setTag(holder);
		}else{
			holder=(ViewHolder) convertView.getTag();
		}
		holder.typeName.setText(list.get(position));
		
		if(item==position){
			holder.icon_duigou.setVisibility(View.VISIBLE);
		}else{
			holder.icon_duigou.setVisibility(View.GONE);
		}
		
		return convertView;
	}
	
	private int item=-1;
	public void setSelectItem(int item){
		this.item=item;
	}
	
	private class ViewHolder{
		private TextView typeName;
		private ImageView icon_duigou;
	}

}
